package com.xiaoxian.user.controller;

import com.xiaoxian.user.service.ILogininfoService;
import com.xiaoxian.user.domain.LoginInfo;
import com.xiaoxian.user.query.LogininfoQuery;
import com.xiaoxian.basic.util.AjaxResult;
import com.xiaoxian.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/logininfo")
public class LogininfoController {
    @Autowired
    public ILogininfoService logininfoService;


    /**
     * 保存和修改公用的
     * @param logininfo  传递的实体
     * @return Ajaxresult转换结果
     */
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody LoginInfo logininfo){

            if( logininfo.getId()!=null)
                logininfoService.update(logininfo);
            else
                logininfoService.add(logininfo);
            return AjaxResult.my();

    }
    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value="/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){

            logininfoService.delete(id);
            return AjaxResult.my();
    }
	
    //获取用户
    @GetMapping("/{id}")
    public LoginInfo get(@PathVariable("id")Long id)
    {
        return logininfoService.queryOne(id);
    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping()
    public List<LoginInfo> list(){

        return logininfoService.queryAll();
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping("/list")
    public PageList<LoginInfo> json(@RequestBody LogininfoQuery query)
    {
        return logininfoService.queryPage(query);
    }
}
